﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;

namespace Ewts.Storage
{
    public partial class CJOByLoadID : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["UserInfo"] != null)
                {
                    if (Request["loadid"] != null && Request["loadid"].ToString().Trim() != "")
                        bindData(Request["loadid"].ToString().Trim());
                }
                else
                {
                    Response.Redirect("/accounts/login.aspx");
                } 
            }

        }

        protected void bindData(string loadid)
        {
            DataLib.Model.LoadNum loadnum = new DataLib.BLL.LoadNum().GetModel(int.Parse(loadid));
            lblLoad.Text = loadnum.loadnum;
            DataTable dt = new DataTable();
            dt = new DataLib.BLL.Cjo().GetCJOList(loadid);
            rept.DataSource = dt;
            rept.DataBind();
        }

        protected string GetLocalUrl(int flag,bool loadstatus)
        {
            string strFile = "CjoReport";
            if (flag == 1)
            {
                if (loadstatus == false)
                    strFile = "CJONonlocalRDLC";
                else
                    strFile = "CjoReport";
            }
            else
            {
                if (loadstatus == false)
                    strFile = "";
                else
                    strFile = "CjoReport";
            }
            return strFile;
        }

        /// <summary>
        /// 获取按钮的状态
        /// </summary>
        /// <param name="status"></param>
        /// <param name="linktype"></param>
        /// <returns></returns>
        protected bool GetEnable(string cjoid)
        {
            DataLib.Model.CJOItem citem = new DataLib.Model.CJOItem();
            DataLib.BLL.CJOItem bcitem = new DataLib.BLL.CJOItem();
            citem = bcitem.GetListByCid(int.Parse(cjoid));

            try
            {
                User curUser = new DataLib.Accounts.Bus.User();
                curUser = (User)Session["UserInfo"];
                if (curUser.UserType != "AD" && citem.cjocreatemanusername.IndexOf(curUser.UserName) < 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
         
        }
    }
}